<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      var randomNum = Math.ceil(Math.random() * 10);
      console.log(randomNum);
      // 计算回答次数
      var count = 0;
      while (count < 5) {
        var youNum = +prompt("请输入您的数字~~~");
        if (Number.isInteger(youNum) && youNum <= 10 && youNum > 0) {
          if (youNum < randomNum) {
            console.log("你输的数字小了");
          } else if (youNum > randomNum) {
            console.log("你输的数字大了");
          } else {
            console.log("恭喜你猜对了！");
            break;
          }
          count++;
        } else {
          console.log("请输入0到10的整数 亲~");
        }
      }

      if (count === 5) {
        console.log("游戏结束正确答案是：" + randomNum);
      }
    </script>
  </body>
</html>
